HAL GFXTIM typical use cases for migration

This section provides information about the applicable HAL GFXTIM architecture use cases.

Note

The major changes per functional blocks provided in HAL2 are:

  • Clock generator: the clock generator configuration has been split into line configuration and frame configuration.

  • Absolute timer: the absolute timer configuration has been removed and has been managed by unitary functions. The set of line/frame counter APIs is optional and can be configured if needed to start the counter from a different default value instead of zero.

  • Relative timer: the relative counter configuration has been merged with the start relative timer API according to the relative mode (continuous or one-shot).

Use case: Starting the GFXTIM with absolute frame line timer

This use case shows how to start the absolute line counter using the frame/line clock generator and handle line compare and overflow events.

Sequence diagram

Absolute line counter start and interrupt callbacks

   @startuml

      participant "User Application" as user
      participant "GFXTIM Driver" as GFXTIM
      participant "NVIC" as nvic

      == GFXTIM Initialization ==
      user->GFXTIM : HAL_GFXTIM_Init()
      == GFXTIM Line Frame Clock Generator ==
      user->GFXTIM : HAL_GFXTIM_ClockGenerator_Config()
      note right : Configure line clock with:\n - clock source, \n - counter source, \n - reload source,\n - reload value

      == GFXTIM Absolute Line ==
      user->GFXTIM : HAL_GFXTIM_AbsoluteTimer_Config()
      note right : Configure the absolute line counter with:\n - counter value, \n - compare value

      user->GFXTIM : HAL_GFXTIM_AbsoluteTimer_Start()

      group  If interrupt is enabled
      nvic->GFXTIM : HAL_GFXTIM_IRQHandler()
      user<--GFXTIM: HAL_GFXTIM_AbsoluteTimer_ALCC1Callback() \n HAL_GFXTIM_AbsoluteTimer_ALCOFCallback()
      note right : Absolute line counter compare 1 event \n Absolute line counter overflow event
      end

      group Optional
      user->GFXTIM : HAL_GFXTIM_ABSTIM_Stop()
      end
      user->GFXTIM : HAL_GFXTIM_DeInit()
      @enduml

Code snippet

HAL1

HAL2

GFXTIM_HandleTypeDef hgfxtim;

hgfxtim.Instance = GFXTIM;
hgfxtim.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim);

/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_RegisterCallback(&hgfxtim,
                       HAL_GFXTIM_ALC_COMPARE1_CB_ID,
                       USER_GFXTIM_ABSTIM_LineCmp1Callback);
HAL_GFXTIM_RegisterCallback(&hgfxtim,
                HAL_GFXTIM_ALC_OVERFLOW_CB_ID,
                USER_GFXTIM_ABSTIM_LineCntOverFlowCallback);

/* Configure the GFXTIM clock generator */
GFXTIM_ClockGeneratorConfigTypeDef ClockGenConfig = {
.LCCHwReloadSrc  = GFXTIM_LCC_HW_RELOAD_SRC_NONE;
.LCCReloadValue  = 159999;
.LCCClockSrc     = GFXTIM_LCC_CLK_SRC_SYSCLOCK;
.LineClockSrc    = GFXTIM_LINE_CLK_SRC_LCC_UNDERFLOW;


.FCCHwReloadSrc  = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCReloadValue  = 0;
.FCCClockSrc     = GFXTIM_FCC_CLK_SRC_DISABLE;
.FrameClockSrc   = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
.LineClockCalib  = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
                                 &pClockGeneratorConfig);

/* Absolute line timer configuration */
GFXTIM_AbsoluteTimerConfigTypeDef pAbsoluteTimerConfig = {
.LineCounterValue       = 0;

.LineCompare1Value      = 1500;


.LineCompare2Value      = 3000;


.FrameCounterValue      = 0;
.FrameCompare1Value     = 0;
.FrameOverflowInterrupt = DISABLE;
.FrameCompare1Interrupt = DISABLE;
/* optional: if interrupt is enabled */
.LineOverflowInterrupt  = ENABLE;
.LineCompare1Interrupt  = ENABLE;
.LineCompare2Interrupt  = ENABLE;
};
HAL_GFXTIM_AbsoluteTimer_Config(&hgfxtim,
 &pAbsoluteTimerConfig);

/* Start the absolute line counter */
HAL_GFXTIM_AbsoluteTimer_Start(&hgfxtim);


/* optional: if interrupt is enabled */



/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_AbsoluteTimer_ALCC1Callback(&hgfxtim);

USER_GFXTIM_AbsoluteTimer_ALCC2Callback(&hgfxtim);

USER_GFXTIM_AbsoluteTimer_ALCOFCallback(&hgfxtim);







/* Disable the absolute line counter */
HAL_GFXTIM_AbsoluteTimer_Stop(&hgfxtim);

/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
hal_gfxtim_handle_t hgfxtim;



/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);

/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_ABSTIM_RegisterLCmpCallback(&hgfxtim,
                        USER_GFXTIM_ABSTIM_LineCmpCallback);

HAL_GFXTIM_ABSTIM_RegisterLCntOverFlowCallback(&hgfxtim,
                 USER_GFXTIM_ABSTIM_LineCntOverFlowCallback);


/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_line_config_t p_line_config = {
.reload_src   = HAL_GFXTIM_CLKGEN_LCNT_NO_RELOAD;
.reload_val   = 159999;
.counter_src  = HAL_GFXTIM_CLKGEN_LINE_COUNT_GFXTIMHCLK;
.clock_src    = HAL_GFXTIM_CLKGEN_LINE_LCNT_UNDERFLOW;
 };
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src  = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val  = 0xFU;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_DISABLE;
.clock_src   = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};


HAL_GFXTIM_CLKGEN_SetConfigLineFrameClock(&hgfxtim,
                                          &p_frame_config,
                                          &p_line_config);

/* Optional :Set the absolute line counter  */
HAL_GFXTIM_ABSTIM_SetLineCounter(&hgfxtim, 0U);
/* Set the absolute line compare 1 value */
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
                                      HAL_GFXTIM_ABSTIM_LINE_COMP_1,
                                      1500U);
/* Set the absolute line compare 2 value */
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
                                      HAL_GFXTIM_ABSTIM_LINE_COMP_2,
                                      3000U);








/* Start the absolute line counter when interrupt is disabled */
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
                        HAL_GFXTIM_ABSTIM_LINE_COUNTER,
                        HAL_GFXTIM_NONE_IT);
/* optional: if interrupt is enabled */
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
                        HAL_GFXTIM_ABSTIM_LINE_COUNTER,
                        HAL_GFXTIM_ABSTIM_LINE_ALL_IT);
/* IRQHandler function */
HAL_GFXTIM_ABSTIM_LineIRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_ABSTIM_LCmpCallback(&hgfxtim,
                             HAL_GFXTIM_ABSTIM_LINE_COMP_1);
USER_GFXTIM_ABSTIM_LCmpCallback(&hgfxtim,
                             HAL_GFXTIM_ABSTIM_LINE_COMP_2);
USER_GFXTIM_ABSTIM_LCntOverFlowCallback(&hgfxtim);
/* optional */
/* Pause the absolute line counter */
HAL_GFXTIM_ABSTIM_Pause(&hgfxtim,
                        HAL_GFXTIM_ABSTIM_LINE_COUNTER);
/* Check that the absolute line counter is paused */
HAL_GFXTIM_ABSTIM_Resume(&hgfxtim,
                         HAL_GFXTIM_ABSTIM_LINE_COUNTER);

/* Disable the absolute line counter */
HAL_GFXTIM_ABSTIM_Stop(&hgfxtim,
                       HAL_GFXTIM_ABSTIM_LINE_COUNTER);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);

Key changes

  1. HAL2 splits clock generator configuration into dedicated line and frame configuration structures.

  2. HAL2 replaces the monolithic absolute timer configuration with unitary line counter and compare configuration APIs.

Use case: Starting the GFXTIM with absolute frame timer

This use case shows how to start the absolute frame counter and handle frame compare and overflow events.

Sequence diagram

Absolute frame counter start and interrupt callbacks

   @startuml

      participant "User Application" as user
      participant "GFXTIM Driver" as GFXTIM
      participant "NVIC" as nvic

      == GFXTIM Initialization ==
      user->GFXTIM : HAL_GFXTIM_Init()
      == GFXTIM Frame Clock Generator ==
      user->GFXTIM : HAL_GFXTIM_ClockGenerator_Config()
      note right : Configure the frame clock with:\n - clock source, \n - counter source, \n - reload source,\n - reload value

      == GFXTIM Absolute Frame ==
      user->GFXTIM : HAL_GFXTIM_AbsoluteTimer_Config()
      note right : Configure the absolute frame counter with:\n - counter value, \n - compare value

      user->GFXTIM : HAL_GFXTIM_AbsoluteTimer_Start()
      group If interrupt is enabled
      nvic->GFXTIM : HAL_GFXTIM_IRQHandler()
      user<--GFXTIM: HAL_GFXTIM_AbsoluteTimer_AFCC1Callback() \n HAL_GFXTIM_AbsoluteTimer_AFCOFCallback()
      note right : Absolute frame counter compare event \n Absolute frame counter overflow event
      end

      group Optional
      user->GFXTIM : HAL_GFXTIM_ABSTIM_Stop()
      end
      user->GFXTIM : HAL_GFXTIM_DeInit()
      @enduml

Code snippet

HAL1

HAL2

 GFXTIM_HandleTypeDef hgfxtim;

 hgfxtim.Instance = GFXTIM;
 hgfxtim.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
 /* GFXTIM initialization */
 HAL_GFXTIM_Init(&hgfxtim);

 /* optional: if interrupt is enabled */
 /* Registering the user callback function */
 HAL_GFXTIM_RegisterCallback(&hgfxtim,
                          HAL_GFXTIM_AFC_COMPARE1_CB_ID,
                          USER_GFXTIM_ABSTIM_FrmCmpCallback);
 HAL_GFXTIM_RegisterCallback(&hgfxtim,
                  HAL_GFXTIM_AFC_OVERFLOW_CB_ID,
                  USER_GFXTIM_ABSTIM_FrmCntOverFlowCallback);
/* Configure the GFXTIM clock generator */
 GFXTIM_ClockGeneratorConfigTypeDef pClockGenConfig = {
 .LineClockSrc    = GFXTIM_LINE_CLK_SRC_FCC_UNDERFLOW;
 .FCCHwReloadSrc  = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
 .FCCReloadValue  = 1;
 .FCCClockSrc     = GFXTIM_FCC_CLK_SRC_HSYNC_RISING;
 .FrameClockSrc   = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
 .LineClockCalib  = GFXTIM_LINE_CLK_CALIB_DISABLE;
 .FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
 };
 HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
                                  &pClockGenConfig);

 /* Configure the GFXTIM clock generator */
 GFXTIM_AbsoluteTimerConfigTypeDef pAbsoluteTimerConfig = {
 .FrameCompare1Value = 0xFFFFA;
 .LineCompare1Value  = 0;
 .LineCompare2Value  = 0;
 .FrameCounterValue  = 0xFFFF0;
 .LineCounterValue   = 0;

   /* optional: if interrupt is enabled */
 .FrameOverflowInterrupt = ENABLE;
 .FrameCompare1Interrupt = ENABLE;
 .LineOverflowInterrupt  = DISABLE;
 .LineCompare1Interrupt  = DISABLE;
 .LineCompare2Interrupt  = DISABLE;
 };
 HAL_GFXTIM_AbsoluteTimer_Config(&hgfxtim,
                                 &pAbsoluteTimerConfig);
 /* Start the absolute line counter */
 HAL_GFXTIM_AbsoluteTimer_Start(&hgfxtim);

 /* optional: if interrupt is enabled */





 /* IRQHandler function */
 HAL_GFXTIM_IRQHandler(&hgfxtim);
 /* Callback function */
 USER_GFXTIM_AbsoluteTimer_AFCC1Callback(&hgfxtim);
 USER_GFXTIM_AbsoluteTimer_ALFOFCallback(&hgfxtim);







 /* Disable the absolute frame counter */
 HAL_GFXTIM_AbsoluteTimer_Stop(&hgfxtim);

 /* GFXTIM Deinitialization */
 HAL_GFXTIM_DeInit(&hgfxtim);
hal_gfxtim_handle_t hgfxtim;



/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);

/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_ABSTIM_RegisterFCmpCallback(&hgfxtim,
                      USER_GFXTIM_ABSTIM_FrameCmpCallback);

HAL_GFXTIM_ABSTIM_RegisterFCntOverFlowCallback(&hgfxtim,
               USER_GFXTIM_ABSTIM_FrameCntOverFlowCallback);

/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_frame_config_t p_frame_config = {

.reload_src  = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val  = 1;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_HSYNC_RISING;
.clock_src   = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};


HAL_GFXTIM_CLKGEN_SetConfigFrameClock(&hgfxtim,
                                      &p_frame_config);


/* Set the absolute frame compare value */
HAL_GFXTIM_ABSTIM_SetFrameCompareValue(&hgfxtim, 0xFFFFA);

/* Set the absolute frame counter */
HAL_GFXTIM_ABSTIM_SetFrameCounter(&hgfxtim, 0xFFFF0);








/* Start the absolute frame counter (interrupt disabled)*/
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
                        HAL_GFXTIM_ABSTIM_FRAME_COUNTER,
                        HAL_GFXTIM_NONE_IT);
/* optional: if interrupt is enabled */
/* Start the absolute frame counter in interrupt mode*/
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
                        HAL_GFXTIM_ABSTIM_FRAME_COUNTER,
                        HAL_GFXTIM_ABSTIM_LINE_ALL_IT);
/* IRQHandler function */
HAL_GFXTIM_ABSTIM_FrameIRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_ABSTIM_FCmpCallback(&hgfxtim):
USER_GFXTIM_ABSTIM_FCntOverFlowCallback(&hgfxtim);
/* optional */
/* Pause the absolute frame counter */
HAL_GFXTIM_ABSTIM_Pause(&hgfxtim,
                        HAL_GFXTIM_ABSTIM_FRAME_COUNTER);
/* Check that the absolute frame counter is paused */
HAL_GFXTIM_ABSTIM_Resume(&hgfxtim,
                         HAL_GFXTIM_ABSTIM_FRAME_COUNTER);

/* Disable the absolute frame counter */
HAL_GFXTIM_ABSTIM_Stop(&hgfxtim,
                       HAL_GFXTIM_ABSTIM_FRAME_COUNTER);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);

Key changes

  1. HAL2 replaces the absolute timer configuration structure with unitary APIs for frame counter and compare configuration.

  2. HAL2 provides a dedicated frame clock generator configuration API.

Related examples in HAL2

Example name

Brief

example_hal_gfxtim_absolute_frame_it

This example is used to generate an interrupt for specific absolute frame.


Use case: Starting the GFXTIM with relative timer

This use case shows how to start the relative frame counter in continuous or one-shot mode and handle frame reload events.

Sequence diagram

Relative timer configuration and start

   @startuml

      participant "User Application" as user
      participant "GFXTIM Driver" as GFXTIM
      participant "NVIC" as nvic

      == GFXTIM Initialization ==
      user->GFXTIM : HAL_GFXTIM_Init()

      == GFXTIM Frame Clock Generator ==
      user->GFXTIM : HAL_GFXTIM_ClockGenerator_Config()
      note right : Configure frame clock generator
      == GFXTIM Relative frame ==
      user->GFXTIM : HAL_GFXTIM_RelativeTimer_Config()
      note right : Configure relative counter with: \n - mode : continuous or oneshot, \n - reload value

      user->GFXTIM : HAL_GFXTIM_RelativeTimer_Start()
      group If interrupt is enabled
      nvic->GFXTIM : HAL_GFXTIM_IRQHandler()
      user<--GFXTIM: HAL_GFXTIM_RelativeTimer_RFC1RCallback()
      note right : Relative frame counter 1 reload event
      end

      group Optional
      user->GFXTIM : HAL_GFXTIM_RelativeTimer_SetReload()
      user->GFXTIM : HAL_GFXTIM_RelativeTimer_ForceReload()
      user->GFXTIM : HAL_GFXTIM_RelativeTimer_Stop()
      end
      user->GFXTIM : HAL_GFXTIM_DeInit()
      @enduml

Code snippet

HAL1

HAL2

GFXTIM_HandleTypeDef hgfxtim;

hgfxtim.Instance = GFXTIM;
hgfxtim.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_RegisterCallback(&hgfxtim,
                   HAL_GFXTIM_RFC1_RELOAD_CB_ID,
                   USER_GFXTIM_RELTIM_FrmCntReloadCallback);
/* Clock generator configuration */
GFXTIM_ClockGeneratorConfigTypeDef pClockGenConfig = {
.LineClockSrc    = GFXTIM_LINE_CLK_SRC_FCC_UNDERFLOW;
.FCCHwReloadSrc  = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCReloadValue  = 1;
.FCCClockSrc     = GFXTIM_FCC_CLK_SRC_DISABLE;
.FrameClockSrc   = GFXTIM_FCC_CLK_SRC_VSYNC_RISING;
.LineClockCalib  = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
                                 &pClockGeneratorConfig);
/* Configure relative timer in continuous mode */
GFXTIM_RelativeTimerConfigTypeDef pRelativeTimerConfig = {
.AutoReloadValue = 200;
.CounterMode = GFXTIM_MODE_CONTINUOUS;
.ReloadInterrupt = ENABLE;
};
HAL_GFXTIM_RelativeTimer_Config(&hgfxtim,
                                &pRelativeTimerConfig,
                               GFXTIM_RELATIVE_TIMER1);
/* Start the relative counter in continuous mode */
HAL_GFXTIM_RelativeTimer_Start(&hgfxtim,
                               GFXTIM_RELATIVE_TIMER1);
/* Configure relative timer in oneshot mode */
GFXTIM_RelativeTimerConfigTypeDef pRelativeTimerConfig = {
.AutoReloadValue = 200;
.CounterMode = GFXTIM_MODE_ONE_SHOT;
.ReloadInterrupt = ENABLE;
};
HAL_GFXTIM_RelativeTimer_Config(&hgfxtim,
                                &pRelativeTimerConfig,
                                GFXTIM_RELATIVE_TIMER1);


 /* Start the absolute line counter in oneshot mode */
 HAL_GFXTIM_RelativeTimer_Start(&hgfxtim,
                                GFXTIM_RELATIVE_TIMER1);



/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_RelativeTimer_RFC1RCallback(&hgfxtim);

/* optional */
/* Set the relative frame counter reload value */
HAL_GFXTIM_RelativeTimer_SetReload(&hgfxtim,
                                HAL_GFXTIM_RELTIM_COUNTER_1,
                                0xFU);
/* Force reload the relative frame counter */
HAL_GFXTIM_RelativeTimer_ForceReload(&hgfxtim,
                                   GFXTIM_RELATIVE_TIMER1);
/* Disable the relative frame counter in continuous mode */
HAL_GFXTIM_RelativeTimer_Stop(&hgfxtim);

/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
hal_gfxtim_handle_t hgfxtim;



/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_RELTIM_RegisterFCntReloadCallback(&hgfxtim,
                   USER_GFXTIM_RELTIM_FrmCntReloadCallback);

/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_frame_config_t p_frame_config = {

.reload_src  = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val  = 1;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_DISABLE;
.clock_src   = HAL_GFXTIM_CLKGEN_FRAME_VSYNC_RISING;
};


HAL_GFXTIM_CLKGEN_SetConfigFrameClock(&hgfxtim,
                                      &p_frame_config);








/* Start the relative frame counter in continuous mode */
HAL_GFXTIM_RELTIM_StartContinuous(&hgfxtim,
                                HAL_GFXTIM_RELTIM_COUNTER_1,
                                200U,
                                HAL_GFXTIM_RELTIM_COUNT_IT);








/* Start the relative frame counter in one shot mode */
HAL_GFXTIM_RELTIM_StartOneShot(&hgfxtim,
                               HAL_GFXTIM_RELTIM_COUNTER_1,
                               200U,
                               HAL_GFXTIM_RELTIM_COUNT_IT);

/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_RELTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_RELTIM_FCntReloadCallback(&hgfxtim,
                               HAL_GFXTIM_RELTIM_COUNTER_1);
/* optional */
/* Set the relative frame counter reload value */
HAL_GFXTIM_RELTIM_SetReloadValue(&hgfxtim,
                                HAL_GFXTIM_RELTIM_COUNTER_1,
                                0xFU);
/* Force reload the relative frame counter */
HAL_GFXTIM_RELTIM_ForceReload(&hgfxtim,
                              GFXTIM_RELATIVE_TIMER1);
/* Stop the relative frame counter in continuous mode */
HAL_GFXTIM_RELTIM_StopContinuous(&hgfxtim,
                               HAL_GFXTIM_RELTIM_COUNTER_1);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);

Key changes

  1. In HAL2, relative timer configuration is merged with the start API, with separate entry points for continuous and one-shot modes.

  2. HAL2 provides dedicated IRQ handling and callback registration for relative timer events.

Related examples in HAL2

Example name

Brief

example_hal_gfxtim_relative_timer_frame_count

This example is used to generate an interrupt for specific relative frame.


Use case: Starting the GFXTIM with event generator

This use case shows how to configure and start the event generator based on absolute line and relative frame events.

Sequence diagram

Configure clocks/timers and start the event generator

   @startuml

      participant "User Application" as user
      participant "GFXTIM Driver" as GFXTIM
      participant "NVIC" as nvic

      == GFXTIM Initialization ==
      user->GFXTIM : HAL_GFXTIM_Init()
      == GFXTIM configuration  ==
      user->GFXTIM : HAL_GFXTIM_ClockGenerator_Config()
      note right : Configure line and frame clock
      user->GFXTIM : HAL_GFXTIM_AbsoluteTimer_Config()
      note right : Configure absolute line counter
      user->GFXTIM : HAL_GFXTIM_RelativeTimer_Config()
      note right : Configure relative frame counter
      user->GFXTIM : HAL_GFXTIM_EventGenerator_Config()
      note right : Configure event generator
      == GFXTIM absolute line and relative frame ==
      user->GFXTIM : HAL_GFXTIM_AbsoluteTimer_Start()
      note right : Start absolute line counter
      user->GFXTIM : HAL_GFXTIM_RelativeTimer_Start()
      note right : Start relative frame counter in continuous mode
      == GFXTIM Event Generator ==
      user->GFXTIM : HAL_GFXTIM_EventGenerator_Enable()
      note right  : Start event generator
      group  If interrupt is enabled
      nvic->GFXTIM : HAL_GFXTIM_IRQHandler()
      user<--GFXTIM: HAL_GFXTIM_EventGenerator_EV1Callback()
      note right : Event generator 1 interrupt
      end

      group  Optional
      user->GFXTIM : HAL_GFXTIM_EventGenerator_Disable()
      end
      user->GFXTIM : HAL_GFXTIM_DeInit()
      @enduml

Code snippet

HAL1

HAL2

GFXTIM_HandleTypeDef hgfxtim = {

.Instance = GFXTIM;
.Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
};
/* GFXTIM initialization */
if (HAL_GFXTIM_Init(&hgfxtim) != HAL_OK);
/* optional: if interrupt is enabled */
/* Registering the user callback function*/
HAL_GFXTIM_RegisterCallback(&hgfxtim,
                         HAL_GFXTIM_EVENT1_CB_ID,
                         USER_GFXTIM_EVENTGEN_EventCallback);
/* Clock generator configuration */
GFXTIM_ClockGeneratorConfigTypeDef pClockGeneratorConfig = {
.LCCClockSrc     = GFXTIM_LCC_CLK_SRC_SYSCLOCK;
.LCCHwReloadSrc  = GFXTIM_LCC_HW_RELOAD_SRC_NONE;
.LCCReloadValue  = 159999;
.LineClockSrc    = GFXTIM_LINE_CLK_SRC_HSYNC_FALLING;



.FCCReloadValue  = 1;
.FCCHwReloadSrc  = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
.FCCClockSrc     = GFXTIM_FCC_CLK_SRC_HSYNC_RISING;
.FrameClockSrc   = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
.LineClockCalib  = GFXTIM_LINE_CLK_CALIB_DISABLE;
.FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
};
HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
                                 &pClockGeneratorConfig);

/* Absolute line configuration */
GFXTIM_AbsoluteTimerConfigTypeDef pAbsoluteTimerConfig = {
.LineCompare1Value = 1;
.LineCompare2Value = 3;
.LineCounterValue = 0;
.LineOverflowInterrupt = DISABLE;
.LineCompare1Interrupt = DISABLE;
.LineCompare2Interrupt = DISABLE;
};
HAL_GFXTIM_AbsoluteTimer_Config(&hgfxtim,
                                &pAbsoluteTimerConfig);
/* Relative frame configuration */
GFXTIM_RelativeTimerConfigTypeDef RTimConfig = {
.AutoReloadValue = 200;
.CounterMode = GFXTIM_MODE_CONTINUOUS;
.ReloadInterrupt = GFXTIM_IT_DISABLE;
};
HAL_GFXTIM_RelativeTimer_Config(&hgfxtim,
                                &RTimConfig,
                                GFXTIM_RELATIVE_TIMER1);
/* Event generator configuration */
GFXTIM_EventGeneratorConfigTypeDef EventConfig = {
.FrameEvent = GFXTIM_FRAME_EVENT_RFC1_RELOAD;
.LineEvent = GFXTIM_LINE_EVENT_ALC1_COMPARE;
.EventInterrupt = GFXTIM_IT_ENABLE;
};
HAL_GFXTIM_EventGenerator_Config(&hgfxtim,
                                 GFXTIM_EVENT_GENERATOR_1,
                                 &EventConfig);

/* Start absolute line */
HAL_GFXTIM_AbsoluteTimer_Start(&hgfxtim);


/* Start relative frame */
HAL_GFXTIM_RelativeTimer_Start(&hgfxtim,
                               GFXTIM_RELATIVE_TIMER1);


/* Enable the event generator */
HAL_GFXTIM_EventGenerator_Enable(&hgfxtim,
                                 GFXTIM_EVENT_GENERATOR_1);

/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_EventGenerator_EV1Callback(&hgfxtim);

/* optional */
/* Stop the event generator 1 */
HAL_GFXTIM_EventGenerator_Disable(&hgfxtim,
                                  GFXTIM_EVENT_GENERATOR_1);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);
  hal_gfxtim_handle_t hgfxtim;




/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function*/
HAL_GFXTIM_EVENTGEN_RegisterEventCallback(&hgfxtim,
                     USER_GFXTIM_EVENTGEN_EventCallback);

/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_line_config_t  p_line_config = {
.counter_src  = HAL_GFXTIM_CLKGEN_LINE_COUNT_NONE;
.reload_src   = HAL_GFXTIM_CLKGEN_LCNT_NO_RELOAD;
.reload_val   = 159999;
.clock_src    = HAL_GFXTIM_CLKGEN_LINE_HSYNC_FALLING;
};
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src  = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val  = 1;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_HSYNC_RISING;
.clock_src   = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};


HAL_GFXTIM_CLKGEN_SetConfigLineFrameClock(&hgfxtim,
                                          &p_frame_config,
                                          &p_line_config);
/* Absolute line configuration */
HAL_GFXTIM_ABSTIM_SetLineCounter(&hgfxtim,0x0U);
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
                                 HAL_GFXTIM_ABSTIM_LINE_COMP_1,
                                 1U);
HAL_GFXTIM_ABSTIM_SetLineCompareValue(&hgfxtim,
                                 HAL_GFXTIM_ABSTIM_LINE_COMP_2,
                                 3U);











/* Configure the event generator */
hal_gfxtim_eventgen_config_t p_config = {
.line_event = HAL_GFXTIM_EVENTGEN_ABS_LCNT_1_COMP;
.frame_event = HAL_GFXTIM_EVENTGEN_REL_FCNT_1_RELOAD;
};
HAL_GFXTIM_EVENTGEN_SetConfig(&hgfxtim,
                              HAL_GFXTIM_EVENTGEN_EVENT_1,
                              &p_config);


/* Start the absolute frame counter */
HAL_GFXTIM_ABSTIM_Start(&hgfxtim,
                        HAL_GFXTIM_ABSTIM_LINE_COUNTER,
                        HAL_GFXTIM_NONE_IT);
/* Start the relative frame counter in continuous mode */
HAL_GFXTIM_RELTIM_StartContinuous(&hgfxtim,
                                  HAL_GFXTIM_RELTIM_COUNTER_1,
                                  200U,
                                  HAL_GFXTIM_RELTIM_COUNT_IT);
/* Start the event generator */
HAL_GFXTIM_EVENTGEN_Start(&hgfxtim,
                          HAL_GFXTIM_EVENTGEN_EVENT_1,
                          HAL_GFXTIM_EVENTGEN_EVENT_IT);
/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_EVENTGEN_IRQHandler(&hgfxtim);
/* Callback function */
USER_GFXTIM_EVENTGEN_EventCallback(&hgfxtim,
                             HAL_GFXTIM_EVENTGEN_EVENT_1);
/* optional */
/* Stop the event generator 1 */
HAL_GFXTIM_EVENTGEN_Stop(&hgfxtim,
                         GFXTIM_EVENTGEN_Event_1);
/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);

Key changes

  1. HAL2 configures and starts the event generator through dedicated EVENTGEN APIs.

  2. HAL2 relies on the HAL2 absolute and relative timer APIs for the line and frame event sources.


Use case: Starting the GFXTIM with watchdog timer

This use case shows how to configure and start the watchdog counter and handle alarm and pre-alarm events.

Sequence diagram

Configure and start the watchdog timer

   @startuml

      participant "User Application" as user
      participant "GFXTIM Driver" as GFXTIM
      participant "NVIC" as nvic

      == GFXTIM Initialization ==
      user->GFXTIM : HAL_GFXTIM_Init()
      == GFXTIM Frame Clock Generator ==
      user->GFXTIM : HAL_GFXTIM_ClockGenerator_Config()
      note right : Configure line and frame clock generator
      == GFXTIM Watchdog Timer ==
      note over user, GFXTIM : Configure and start watchdog counter
      user->GFXTIM : HAL_GFXTIM_WatchdogTimer_Config()
      user->GFXTIM : HAL_GFXTIM_WatchdogTimer_Enable()
      group If interrupt is enabled
      nvic->GFXTIM : HAL_GFXTIM_IRQHandler()
      user<--GFXTIM: USER_GFXTIM_WatchdogTimer_AlarmCallback() \n USER_GFXTIM_WatchdogTimer_PreAlarmCallback()
      note right : Watchdog alarm interrupt \n Watchdog pre alarm interrupt
      end


      group Optional
      user->GFXTIM : HAL_GFXTIM_WDG_Refresh()
      end
      user->GFXTIM : HAL_GFXTIM_WatchdogTimer_Disable()
      user->GFXTIM : HAL_GFXTIM_DeInit()
      @enduml

Code snippet

HAL1

HAL2

 GFXTIM_HandleTypeDef hgfxtim = {

 .Instance = GFXTIM;
 .Init.SynchroSrc = GFXTIM_SYNC_SRC_HSYNC_VSYNC_0;
 };
 /* GFXTIM initialization */
 HAL_GFXTIM_Init(&hgfxtim);
/* optional: if interrupt is enabled */
/* Registering the user callback function*/
 HAL_GFXTIM_RegisterCallback(&hgfxtim,
             HAL_GFXTIM_WDG_ALARM_CB_ID,
             USER_GFXTIM_WDG_AlarmCallback);
 HAL_GFXTIM_RegisterCallback(&hgfxtim,
             HAL_GFXTIM_WDG_PRE_ALARM_CB_ID,
             USER_GFXTIM_WDG_PreAlarmCallback);

 /* Clock generator configuration */
 GFXTIM_ClockGeneratorConfigTypeDef pClockGenConfig = {
 .LCCHwReloadSrc  = GFXTIM_LCC_HW_RELOAD_SRC_NONE;
 .LCCReloadValue  = 159999;
 .LCCClockSrc     = GFXTIM_LCC_CLK_SRC_SYSCLOCK;
 .LineClockSrc    = GFXTIM_LINE_CLK_SRC_FCC_UNDERFLOW;


 .FCCHwReloadSrc  = GFXTIM_FCC_HW_RELOAD_SRC_NONE;
 .FCCReloadValue  = 0xFU;
 .FCCClockSrc     = GFXTIM_FRAME_CLK_SRC_LCC_UNDERFLOW;
 .FrameClockSrc   = GFXTIM_FRAME_CLK_SRC_FCC_UNDERFLOW;
 .LineClockCalib  = GFXTIM_LINE_CLK_CALIB_DISABLE;
 .FrameClockCalib = GFXTIM_FRAME_CLK_CALIB_DISABLE;
 };
 HAL_GFXTIM_ClockGenerator_Config(&hgfxtim,
                                  &pClockGenConfig);

 /* Watchdog timer configuration */
 GFXTIM_WatchdogConfigTypeDef WdgConfig = {
 .ClockSrc = GFXTIM_WATCHDOG_CLK_SRC_LINE_CLK;
 .AutoReloadValue = 1000;
 .PreAlarmValue = 500;
 .AlarmInterrupt = GFXTIM_IT_ENABLE;
 .PreAlarmInterrupt = GFXTIM_IT_ENABLE;
 .HwReloadConfig = GFXTIM_WATCHDOG_HW_RELOAD_DISABLE;
 };
 HAL_GFXTIM_WatchdogTimer_Config(&hgfxtim, &WdgConfig);

 /* Enable the watchdog timer */
 HAL_GFXTIM_WatchdogTimer_Enable(&hgfxtim);




 /* optional: if interrupt is enabled */
 /* IRQHandler function */
 HAL_GFXTIM_IRQHandler(&hgfxtim);
 /* Watchdog alarm callback function */
 HAL_GFXTIM_WDG_AlarmCallback(&hgfxtim);
 /* Watchdog pre alarm callback function */
 HAL_GFXTIM_WDG_PreAlarmCallback(&hgfxtim);

 /* optional */
 /* Refresh the watchdog timer */
 HAL_GFXTIM_WatchdogTimer_Refresh(&hgfxtim);
 /* Disable the watchdog timer */
 HAL_GFXTIM_WatchdogTimer_Disable(&hgfxtim);

 /* GFXTIM Deinitialization */
 HAL_GFXTIM_DeInit(&hgfxtim);
hal_gfxtim_handle_t hgfxtim;




/* GFXTIM initialization */
HAL_GFXTIM_Init(&hgfxtim, HAL_GFXTIM);
/* optional: if interrupt is enabled */
/* Registering the user callback function */
HAL_GFXTIM_WDG_RegisterAlarmCallback(&hgfxtim,
                USER_GFXTIM_WDG_AlarmCallback);

HAL_GFXTIM_WDG_RegisterPreAlarmCallback(&hgfxtim,
                USER_GFXTIM_WDG_PreAlarmCallback);


/* Configure the GFXTIM clock generator */
hal_gfxtim_clkgen_line_config_t p_line_config = {
.reload_src   = HAL_GFXTIM_CLKGEN_LCNT_NO_RELOAD;
.reload_val   = 159999;
.counter_src  = HAL_GFXTIM_CLKGEN_LINE_COUNT_GFXTIMHCLK;
.clock_src    = HAL_GFXTIM_CLKGEN_LINE_FCNT_UNDERFLOW;
};
hal_gfxtim_clkgen_frame_config_t p_frame_config = {
.reload_src  = HAL_GFXTIM_CLKGEN_FCNT_NO_RELOAD;
.reload_val  = 0xFU;
.counter_src = HAL_GFXTIM_CLKGEN_FCNT_DISABLE;
.clock_src   = HAL_GFXTIM_CLKGEN_FRAME_FCNT_UNDERFLOW;
};


HAL_GFXTIM_CLKGEN_SetConfigFrameClock(&hgfxtim,
                                      &p_frame_config,
                                      &p_line_config);
/* Watchdog timer configuration */
hal_gfxtim_wdg_config_t p_wdg_config;
p_wdg_config.src = HAL_GFXTIM_WDG_CLK_LINE_CLK;





HAL_GFXTIM_WDG_SetConfig(&hgfxtim, &p_wdg_config);

/* Start the watchdog timer */
HAL_GFXTIM_WDG_Start(&hgfxtim,
                     1000U,
                     500U,
                     HAL_GFXTIM_WDG_ALL_IT);

/* optional: if interrupt is enabled */
/* IRQHandler function */
HAL_GFXTIM_WDG_IRQHandler(&hgfxtim);
/* Watchdog alarm callback function */
USER_GFXTIM_WatchdogTimer_AlarmCallback(&hgfxtim);
/* Watchdog pre alarm callback function */
USER_GFXTIM_WatchdogTimer_PreAlarmCallback(&hgfxtim);

/* optional */
/* Refresh the watchdog timer */
HAL_GFXTIM_WatchdogTimer_Refresh(&hgfxtim);
/* Disable the watchdog timer */
HAL_GFXTIM_WDG_Stop(&hgfxtim);

/* GFXTIM Deinitialization */
HAL_GFXTIM_DeInit(&hgfxtim);

Key changes

  1. In HAL2, watchdog configuration and start are separated into dedicated HAL_GFXTIM_WDG_SetConfig() and HAL_GFXTIM_WDG_Start() APIs.

  2. HAL2 provides dedicated IRQ handling and callback registration APIs for watchdog alarm and pre-alarm events.

Related examples in HAL2

Example name

Brief

example_hal_gfxtim_watchdog_alarm_pre-alarm

This example is used to generate interrupts on alarm and pre-alarm events.